'''class Node:
  def __init__(self, id):
    self.id = id # A string (number?)
  
  def __str__(self):
    return 'Node '+str(id)

class Edge:
  def __init__(self, src, dst):
    self.src = src # src and dst should be Nodes.
    self.dst = dst
  
  def __str__(self):
    return 'Edge from '+str(src)+' to '+str(dst)'''

if __name__ == '__main__':
  def getOutgoingNeighbors(node):
    result = []
    for e in edges:
      if e[0] == node:
        result.append(e[1])
    return result
  
  def getIncomingNeighbors(node):
    result = []
    for e in edges:
      if e[1] == node:
        result.append(e[0])
    return result
  
  def getDistance(a, b, closed=[]):
    "Gets the distance from a to b."
    return 0 # TODO
  
  f = open('testinput1.txt', 'r')
  nodes = set()
  edges = set()
  unreciprocatedEdges = set()
  candidateEdges = set()
  for line in f:
    l = line.split()
    id = l[0] # String?
    incoming = int(l[1])
    count = int(l[2])
    others = l[3:-1] # A list of IDs.
    print l
    print 'ID: ', id
    print 'Incoming? ', incoming
    print 'Count: ', count
    print others
    assert (len(others) == count)
    
    nodes.add(id)
    for o in others:
      if incoming:
        edges.add((o, id))
      else:
        edges.add((id, o))
  
  print nodes
  print edges
  print getOutgoingNeighbors('12345')
  print getIncomingNeighbors('12345')
  
  for e in edges:
    if (e[1], e[0]) not in edges:
      unreciprocatedEdges.add(e)
      candidateEdges.add((e[1], e[0]))
  
  print 'Unreciprocated edges: ', unreciprocatedEdges
